<template>
	<div class="pendingDisposal">

		<div class="clearfloat">
			<el-button type="success" icon="el-icon-plus" circle class="fl" @click="quickApply" v-if="$store.state.user.role_id == 2"></el-button>
			<el-button v-no-more-click:3000 class="ml10 fr" @click="addOrder" v-if="$store.state.user.role_id == 4">+添加订单</el-button>
			<!-- <el-button v-no-more-click:3000 type='success' >快速申请</el-button> -->
			<orderStatistics :myInfo ='myInfo' :roleID='roleID' />
			<el-popover placement="left" trigger="click">
				<template>
					<el-checkbox v-model="tableHeader.checked" @change="selectAll">全选</el-checkbox>
					<br />
					<el-checkbox v-if='roleID == 1 || roleID == 4 || roleID == 7' v-model="tableHeader.checked0">等待接单时长</el-checkbox>
					<br v-if='roleID == 1 || roleID == 4 || roleID == 7' />
					<el-checkbox v-model="tableHeader.checked1">订单编号</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked2">拟申报专利名称</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked7">专利类型</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked12">附图</el-checkbox>
					<br />
					<el-checkbox v-if='roleID != 4' v-model="tableHeader.checked11">流程人员</el-checkbox>
					<br v-if='roleID != 4' />
					<el-checkbox v-model="tableHeader.checked3">联络人</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked4">电话</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked5">邮箱</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked6">流程状态</el-checkbox>
					<br />
					<el-checkbox v-if='roleID != 2' v-model="tableHeader.checked13">备注</el-checkbox>
					<br v-if='roleID != 2' />
					<el-checkbox v-if="roleID!=2" v-model="tableHeader.checked8">发明人</el-checkbox>
					<br v-if="roleID!=2" />
					<el-checkbox v-if="roleID!=2" v-model="tableHeader.checked9">专利权人</el-checkbox>
					<br v-if="roleID!=2" />
					<el-checkbox v-model="tableHeader.checked10">提交时间</el-checkbox>
					<br />
				</template>
				<el-button style="float: right;margin-bottom: 5px;margin-top: 0;" slot="reference" icon="el-icon-arrow-down">显示字段</el-button>
			</el-popover>
			<span v-if="roleID!=2" class="down-execel" @click="exportExcel('未处理订单','xlsx')">
				<i class="el-icon-download"></i> <a href="javascript:;">导出列表</a>
			</span>
			<a id="JS_DOWNLOAD" href=""></a>
			<!-- 列表查找 -->
			<span class="down-execel">
				<!-- <Icon type="ios-funnel-outline" /><a href="javascript:;">筛选条件</a> -->
				<Poptip v-model="showFilter" placement="bottom-end" @on-popper-show ='getAllAgent'>
					<!-- <Icon type="ios-funnel-outline" /> -->
					<i class="el-icon-search poptip-condition-add"></i>
					<a href="javascript:;">列表查找</a>
					<!-- <div slot="title"><i></i></div> -->
					<div slot="content">
						<Poptip v-model="showFilterCondition" placement="bottom-start" class='poptip-condition'>
							<i class="el-icon-plus poptip-condition-add"></i>
							<a href="javascript:;" class='poptip-condition-add'>添加过滤条件</a>


							<div slot="content" class="condition-list">
								<ul>
									<!-- <template v-if='roleID === 4' >
										<li v-for="(item, index) in columns2" :key="index" class='poptip-condition-item' @click="addFilterCondition(item)">{{item.label}}</li>
									</template> -->
									<li  v-for="(item, index) in columns" :key="index" class='poptip-condition-item' @click="addFilterCondition(item)">{{item.label}}</li>
								</ul>
							</div>
						</Poptip>

						<el-form :model="conditionForm" ref="conditionForm" label-width="120px" class="demo-dynamic" @submit.native.prevent>
							<el-form-item v-for="(condition, index) in conditionForm.condition" :label="condition.label" :key="condition.key"
									:prop="'condition.' + index + '.value'" :rules="{
										required: true, message: condition.label +'不能为空', trigger: 'blur'
									}">
								<el-date-picker
									v-model="submitTime"
									type="daterange"
									placeholder="选择日期"
									value-format="yyyy-MM-dd"
									@change = 'changInput'
									:validate-event='false'
									size="small"
									v-if='condition.label === "提交时间"'>
								</el-date-picker>

								<el-select v-else-if='condition.label === "专利类型"' v-model="condition.value" placeholder="请选择专利类型" size="small">
									<el-option label="发明专利" value="发明专利"></el-option>
									<el-option label="实用新型" value="实用新型"></el-option>
									<el-option label="外观设计" value="外观设计"></el-option>
									<el-option label="不确定" value="不确定"></el-option>
								</el-select>

								<el-select
									size="small"
									filterable
									v-model="condition.value"
									v-else-if='condition.label === "流程人员"'>
									<el-option
										v-for="item in processOptions"
										:key="item.id"
										:label="roleID == 2 ? item.email_work.split('@')[0].split('followup')[1] : item.name"
										:value="item.id">
									</el-option>
								</el-select>

								<el-input v-else size="small" v-model="condition.value" @keyup.enter.native="submitsearch('conditionForm')"></el-input>
								<el-button @click.stop="removeDomain(condition)" size="mini">删除</el-button>
							</el-form-item>
							<div class='btns'>
								<el-button @click="submitsearch('conditionForm')" size="mini">查询</el-button>
								<el-button @click.stop="resetForm('conditionForm')" size="mini">重置</el-button>
							</div>

						</el-form>
					</div>
				</Poptip>
			</span>
		</div>

		<el-table
			v-if="table_show"
			id="orderTb"
			ref="orderTb"
			:data="tableData"
			border
			style="width: 100%;"
			v-loading="loading"
			height="87%"
			@row-click="lookOrder"
			@sort-change='tableSortChange'
			@selection-change="handleSelectionChange">
			<!-- <el-table-column show-overflow-tooltip type="selection" width="55">
			</el-table-column> -->
			<el-table-column show-overflow-tooltip key="1" prop="id" label="ID" width="60" align="left" v-if='checked99'>
				<template slot-scope="scope">{{(scope.$index+1)+(currentPage-1)*tableSize}}</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip key="2" v-if="tableHeader.checked0 && (roleID == 1 || roleID == 4 || roleID == 7)" prop="created_at" label="等待接单时长(天)" width="160" align="left" sortable >
				<template slot-scope="scope">
					<span :class="getOrderTime(scope.row.created_at) > 2 ? 'font_danger' : ''">{{getOrderTime(scope.row.created_at)}}</span>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip key="3" sortable='custom' v-if="tableHeader.checked1" prop="order_number" label="订单编号" min-width="180" align="left"></el-table-column>
			<el-table-column show-overflow-tooltip key="8" v-if="tableHeader.checked6" prop="status" label="流程状态" min-width="120" align="left" sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip key="4" v-if="tableHeader.checked2" prop="patent_name" label="拟申报专利名称" min-width="180" sortable='custom' align="left"></el-table-column>
			<el-table-column show-overflow-tooltip prop="type" key="9" v-if="tableHeader.checked7" label="专利类型" min-width="130" sortable='custom' align="left"></el-table-column>
			<el-table-column
				label="附图"
				sortable='custom'
				key="15"
				v-if="tableHeader.checked12"
				min-width="150"
				align="left">
				<template slot-scope="scope">
					<div v-if="scope.row.imgArr" class="img-wrap" @click.stop>
						<pre-img
							:smallImg="scope.row.imgArr"
							:bigImg="scope.row.imgArr2"
							class="pre-img">
						</pre-img>
					</div>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip key="5" v-if="tableHeader.checked3" prop="liaisons" label="联络人" min-width="100" align="left" sortable='custom'>
				<template slot-scope="scope">
					<span>{{scope.row.liaisons}}</span>
					<Tooltip  v-if="roleID == 2 && $store.state.is_teacher == 1"  content="点我留言">
						<i class="el-icon-chat-dot-round leaveWord"  @click.stop="leaveWord(scope.row, '1')"></i>
					</Tooltip>
				</template>
			</el-table-column>
			<div v-if="roleID != 2">
				<el-table-column show-overflow-tooltip key="10" v-if="tableHeader.checked8 " prop="user_name" label="发明人" width="120" sortable='custom'
					align="left"></el-table-column>
				<el-table-column show-overflow-tooltip key="11" v-if="tableHeader.checked9" prop="patent_user" label="专利权人" width="120" sortable='custom'
					align="left"></el-table-column>
			</div>
			<el-table-column show-overflow-tooltip key="6" v-if="tableHeader.checked4" prop="liaisons_tel" label="电话" min-width="120" align="left" sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip key="7" v-if="tableHeader.checked5" prop="liaisons_email" label="邮箱" min-width="150" align="left" sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip v-if="tableHeader.checked13 && roleID != 2" prop="remarks" label="备注" min-width="120" align="left" sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip key="13" v-if="tableHeader.checked11" label="流程人员"  min-width="110" prop="process" align="left" sortable>
				<template slot-scope="scope">
					<span v-if="roleID == 4">{{ scope.row.process ? scope.row.process.name : '' }}</span>
					<span v-else>{{ scope.row.process | processNumber }}</span>
					<Tooltip  v-if="roleID == 2 && $store.state.is_teacher == 1"  content="点我留言">
						<i class="el-icon-chat-dot-round leaveWord"  @click.stop="leaveWord(scope.row, '2')"></i>
					</Tooltip>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip key="12" v-if="tableHeader.checked10" prop="submitTime" label="提交时间" min-width="160" align="left" sortable >
				<template slot-scope="scope">{{ findData(scope.row) }}</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip v-if="roleID == 2 && checked99" width="100" :fixed="isFixed" align="center">
				<template slot="header">
					<span class="tableLastCol">操作</span>
				</template>
				<template slot-scope="scope">
					
					<el-popover
						v-if='$store.state.user.is_teacher == 1'
						placement="left"
						width="120"
						trigger="click">
						<el-button v-no-more-click:3000 type="danger" size="small" @click.stop="orderTaking(scope.row)">自己接单</el-button>
						<br/>
						<el-button v-no-more-click:3000 type="warning" class='mt10' size="small" @click.stop="distributeOrder(scope.row)">分配订单</el-button>
						<el-button slot="reference" type="danger" size="small" @click.stop='showTakingBtns(scope.row)'>接单</el-button>
					</el-popover>
					<el-button v-else v-no-more-click:3000  type="danger" size="small" @click.stop="orderTaking(scope.row)">接单</el-button>

				</template>
			</el-table-column>
		</el-table>

		<!-- 导出用的 -->
		<el-table v-show='false' id="orderTbTemp" ref="orderTbTemp" :data="tableData2" border style="width: 100%;"
			v-loading="loading" @row-click="lookOrder" @selection-change="handleSelectionChange">
			<!-- <el-table-column show-overflow-tooltip type="selection" width="55">
			</el-table-column> -->
			<el-table-column show-overflow-tooltip key="1" sortable prop="id" label="ID" width="60" align="left">
				<!-- <template slot-scope="scope">{{(scope.$index+1)+(currentPage-1)*tableSize}}</template> -->
			</el-table-column>
			<el-table-column show-overflow-tooltip key="2" sortable v-if="tableHeader.checked0" prop="id" label="等待接单时长" width="140" align="left">
				<template slot-scope="scope">{{getOrderTime(scope.row.created_at)}}</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip key="3" sortable v-if="tableHeader.checked1" prop="order_number" label="订单编号" width="180" align="left"></el-table-column>
			<el-table-column show-overflow-tooltip key="4" v-if="tableHeader.checked2" prop="patent_name" label="拟申报专利名称" width="200" align="left"></el-table-column>
			<el-table-column show-overflow-tooltip prop="type" key="9" v-if="tableHeader.checked7" label="专利类型" width="180" sortable align="left"></el-table-column>
			<el-table-column show-overflow-tooltip key="13" v-if="tableHeader.checked11" label="流程人员" width="180" prop="process.name" sortable align="left">
				<template slot-scope="scope">
					{{ scope.row.process | processNumber}}
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip key="5" v-if="tableHeader.checked3" prop="liaisons" label="联络人" width="100" align="left"></el-table-column>
			<el-table-column show-overflow-tooltip key="6" v-if="tableHeader.checked4" prop="liaisons_tel" label="电话" width="120" align="left"></el-table-column>
			<el-table-column show-overflow-tooltip key="7" v-if="tableHeader.checked5" prop="liaisons_email" label="邮箱" width="200" align="left"></el-table-column>
			<el-table-column show-overflow-tooltip key="8" v-if="tableHeader.checked6" prop="status" label="流程状态" width="100"
				align="left"></el-table-column>
			<div v-if="roleID != 2">
				<el-table-column show-overflow-tooltip  key="10" v-if="tableHeader.checked8 " prop="user_name" label="发明人" width="100"
					align="left"></el-table-column>
				<el-table-column show-overflow-tooltip key="11" v-if="tableHeader.checked9" prop="patent_user" label="专利权人" width="100"
					align="left"></el-table-column>
			</div>
			<el-table-column show-overflow-tooltip v-if="tableHeader.checked13" prop="remarks" label="备注" width="120" align="left" sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip key="12" v-if="tableHeader.checked10" label="提交时间" width="190" sortable align="left">
				<template slot-scope="scope">{{ findData(scope.row) }}</template>
			</el-table-column>

			<el-table-column show-overflow-tooltip v-if="roleID == 2" :fixed="isFixed" width="80" align="center">
				<template slot="header">
					<span class="tableLastCol">操作</span>
				</template>
				<template slot-scope="scope">
					<el-popover
						placement="right"
						width="400"
						trigger="click">
						<el-button v-no-more-click:3000 type="danger" size="small" @click.stop="orderTaking(scope.row)">自己接单</el-button>
						<br/>
						<el-button v-no-more-click:3000 type="danger" class='mt10' size="small" @click.stop="distributeOrder(scope.row)">分配订单</el-button>
						<el-button slot="reference">接单</el-button>
					</el-popover>
				</template>
			</el-table-column>
		</el-table>

		<el-pagination class="pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
		:page-sizes="pageSizes" :page-size="Number(pageSize)" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>

		<!-- 查看 -->
		<lookDialog
			@chageData="search"
			:order_id="order_id"
			:order_process="order_process"
			:order_agent="order_agent"
			:formPendingDisposal='true'
			ref="orderDialog"
			@changeList="onChangeList"
			@clickOrderTaking="orderTaking">
		</lookDialog>

		<!-- 进度 -->
		<processScheduleDialog ref="scheduleDialog" :stepsText="stepsText"></processScheduleDialog>

		<!-- 修改资料 -->
		<editDialog ref="editInfo"></editDialog>

		<!-- 新增订单 -->
		<order-operate ref="order-operate" @refresh="search"></order-operate>


		<!-- 导师分配代理人 -->
		<distributeOrder ref='distributeOrder' @refresh='search'></distributeOrder>
	</div>
</template>

<script>
	import {
		orderTaking,
		getOrderList
	} from "~/api/order";
	import editDialog from "~/components/editDialog"; //修改邮箱弹出层
	import lookDialog from "./dialogPage/dialogOrder"; //查看弹出层
	import processScheduleDialog from "./dialogPage/processSchedule"; //进度弹出层

	// 方法的JS文件
	import orderFn from "./getOrderList";

	//导出
	import { exportExcel,agentLeaveWord } from "~/util/index"
	import orderStatistics from "~/components/orderStatistics"
	import orderOperate from './dialogPage/order-operate'
	// import agentOrderOperate from './dialogPage/agentOrder-operate'
	import { downloadedOrderWord } from '~/api/order'
	import preImg from '~/components/pre-img'
	import { getMyInfo } from "~/api/user"
	import distributeOrder from './dialogPage/distributeOrder'
	export default {
		head: {
			title: "未处理订单"
		},
		name: "pendingDisposal",
		components: {
			orderOperate,
			lookDialog,
			processScheduleDialog,
			editDialog,
			orderStatistics,
			preImg,
			distributeOrder
			// agentOrderOperate
		},
		data() {
			return {
				order_id: '',
				order_process: {},
				order_agent: {},
				loading: true,
				tableData: [],
				tableData2: [],
				selectTableData: {}, //勾选的数据。为了统计每页合计勾选的数据。
				//默认域名
				baseUrl: global.baseurl,
				roleID: 1,
				isFixed: 'right',
				// 分页
				tableSize: 10, //一页几条
				currentPage: 1, //目前在第几页
				pageSizes: [25, 50], //一页可以几条
				total: 0,

				myInfo: {},
				checked99: true,

				tableHeader: {
					checked: true,
					checked0: true,
					checked1: true,
					checked2: true,
					checked3: true,
					checked4: true,
					checked5: true,
					checked6: true,
					checked7: true,
					checked8: true,
					checked9: true,
					checked10: true,
					checked11: true,
					checked12: true,
					checked13: true,
				},
				table_show: true,
				showFilter: false, // 控制显示筛选条件
				showFilterCondition: false,
				conditionForm: {
					condition: []
				}, //筛选条件
				columns: [
					{
						label: '订单编号',
						id: 3,
						parameter: 'order_number'
					},
					{
						label: '拟申报专利名称',
						id: 4,
						parameter: 'patent_name'
					},
					{
						label: '联络人',
						id: 5,
						parameter: 'liaisons'
					},
					{
						label: '电话',
						id: 6,
						parameter: 'liaisons_tel'
					},
					{
						label: '流程人员',
						id: 5,
						parameter: 'process_id'
					},
					{
						label: '发明人',
						id: 8,
						parameter: 'user_name'
					},
					{
						label: '专利权人',
						id: 9,
						parameter: 'patent_user'
					},
					{
						label: '提交时间',
						id: 10,
						parameter: 'subimt_time'
					},
					{
						label: '专利类型',
						id: 11,
						parameter: 'type'
					},
					{
						label: '邮箱',
						id: 1,
						parameter: 'liaisons_email'
					},
				],
				columns2: [
					{
						label: '订单编号',
						id: 3,
						parameter: 'order_number'
					},
					{
						label: '拟申报专利名称',
						id: 4,
						parameter: 'patent_name'
					},
					{
						label: '联络人',
						id: 5,
						parameter: 'liaisons'
					},
					{
						label: '电话',
						id: 6,
						parameter: 'liaisons_tel'
					},
					{
						label: '发明人',
						id: 8,
						parameter: 'user_name'
					},
					{
						label: '专利权人',
						id: 9,
						parameter: 'patent_user'
					},
					{
						label: '提交时间',
						id: 10,
						parameter: 'subimt_time'
					},
					{
						label: '专利类型',
						id: 11,
						parameter: 'type'
					},
					{
						label: '邮箱',
						id: 1,
						parameter: 'liaisons_email'
					},
				],
				lastTime: 0,
				searchValue: '',
				submitTime: [],
				formProcess: {},
				paramsByOrder: {
					status: "待接单"
				},
				stepsText: ['提交申请', '代理人接单', '案件撰写', '案件质控', '发明人定稿', '案件上传', '递交国知局'],
				restaurants2: [],
				downloadDOM: '',
				processOptions: []
			};
		},
		mounted () {
			this.downloadDOM = document.getElementById('JS_DOWNLOAD')
		},
		async asyncData({
			$axios,
			store
			}) {
			let paramsByOrder = {
				status: "待接单"
			};
			if (store.state.user.role_id == 4) {
				paramsByOrder.process_id = store.state.user.id;
			}
			return orderFn.getOrderByasync($axios, store, paramsByOrder);
		},
		created() {},
		methods: {
			showTakingBtns(data) {

			},
			distributeOrder(data) {
				this.$refs['distributeOrder'].show(data)
			},
			leaveWord (data, type) {
				agentLeaveWord(data, type, this)
			},
			quickApply () {
				this.$router.push('/user/apply?sumbit_type=2')
			},
			async getMyinfo (params) {
				let myInfo = await getMyInfo(this.$axios, params);
				if (myInfo.data.status == 'success') {
					this.$store.commit("setRoleInfo",myInfo.data.data)
					this.$store.commit("setUser",myInfo.data.data)
					this.myInfo = myInfo.data.data
					this.roleID = this.myInfo.role_id
				}
			},
			selectAll(val) {
				for( let i in this.tableHeader) {
					this.tableHeader[i] = val
				}
			},
			tableDataRefresh() {
				if (!this.paramsByOrder.process_id) {
					if (this.$store.state.user.role_id == 4) {
						this.paramsByOrder.process_id = this.$store.state.user.id;
					}
				}
				orderFn.getData(this.$axios, this.paramsByOrder, this)
			},
			addOrder() {
				if (this.$store.state.user.role_id == 4) {
					this.$refs['order-operate'].showOn()
				}
			},
			//选择一页几条
			async handleSizeChange(size) {
				this.paramsByOrder.perPage = size
				this.paramsByOrder.page = 1
				if (this.$store.state.user.role_id == 4) {
					this.paramsByOrder.process_id = this.$store.state.user.id;
				}
				let data = await orderFn.getOrderByasync(this.$axios, this.$store, this.paramsByOrder);
				for (let key in data) {
					this[key] = data[key];
				}
			},
			//选择第几页
			async handleCurrentChange(val) {
				this.currentPage = val;
				// let parms = this.paramsByOrder
				this.paramsByOrder.page = val

				if (!this.paramsByOrder.process_id) {
					if (this.$store.state.user.role_id == 4) {
						this.paramsByOrder.process_id = this.$store.state.user.id;
					}
				}
				let data = await orderFn.getOrderByasync(this.$axios, this.$store, this.paramsByOrder);
				for (let key in data) {
					this[key] = data[key];
				}
			},

			// 分配后刷新列表
			onChangeList() {
				this.getData();
			},

			//查看 管理员
			lookOrder(row, column, event) {
				if (window.getSelection().toString() === '') {
					this.order_process = row.process;
					this.order_agent = row.agent || {};
					this.$refs.orderDialog.showDialog(row.id, "待接单");
					this.order_id = row.order_number;
				}
			},

			//查看 代理人
			lookOrderByAgent(val) {
				this.$refs.orderDialog.showDialog(val.id, "待接单");
			},
			//流程进度
			editOrder(val) {
				this.$refs.scheduleDialog.showDialog(val);
			},

			//获取表格数据
			getData() {
				this.roleID = this.$store.state.user.role_id;
				// let paramsByOrder = {
				// 	status: "待接单"
				// };
				if (!this.paramsByOrder.process_id) {
					if (this.$store.state.user.role_id == 4) {
						this.paramsByOrder.process_id = this.$store.state.user.id;
					}
				}
				orderFn.getData(this.$axios, this.paramsByOrder, this)
				this.getMyinfo()
			},
			//删除
			delOrder(val) {
				let paramsByOrder = {
					status: "代理人撰写中,案件内审中,案件修改中,发明人确认定稿中,上报文件上传中"
				};
				orderFn.delOrderByJS(this.$axios, val.id, paramsByOrder, this);
			},

			isEmpty(obj) {
				if (typeof obj == "undefined" || obj == null || obj == "") {
					return true;
				} else {
					return false;
				}
			},

			//关闭
			handleClose() {
				this.email_work = "";
				this.dialogFormVisible = false;
			},

			// 代理接单
			orderTaking(val) {
				let agentObj = this.$store.state.user;
				if (
					agentObj.email_work == "undefined" ||
					agentObj.email_work == null ||
					agentObj.email_work == ""
				) {
					this.$alert("您还没有工作邮箱，请先修改资料", "提示", {
						confirmButtonText: "确定",
						center: true,
						callback: action => {
							this.$refs.editInfo.showDialog();
						}
					});
				} else {
					this.$confirm("确认接单吗", "提示", {
							cancelButtonText: "取消",
							confirmButtonText: "确定",
							center: true,
							type: "warning"
						})
						.then(() => {
							let obj = {
								order: val.id,
								agent: this.$store.state.user.id
							};
							orderTaking(this.$axios, obj)
								.then(({
									data
								}) => {
									if (data.status == "success") {
										this.$confirm('请在接单后的<i class="font_danger">25</i>天内完成订单，如案件撰写超时，案件结算时将按<i class="font_danger">20</i>元/天扣费！！是否下载接单文件？', '接单成功!', {
											confirmButtonText: '确定',
											cancelButtonText: '取消',
											dangerouslyUseHTMLString: true,
											center: true,
										}).then ( () => {
											this.download(val.id)
										}).catch(() => {

										})
										this.getData()
									} else {
										// this.$message({
										// 	type: "error",
										// 	message: data.message
										// })

										this.$alert(data.message, '提示', {
											confirmButtonText: '确定',
											center: true,
											callback: action => {
											}
										})
									}
								})
								.catch(err => {
									console.log(err);
									this.getData()
								});
						})
						.catch(() => {
						});
				}
			},

			// 时间
			findData(val) {
				let statusArr = val.statuss;
				let statusTime = "";
				for (const i in statusArr) {
					if (statusArr[i].id == 1) {
						statusTime = statusArr[i].pivot.created_at;
					}
				}
				return statusTime;
			},
			async download(id) {
					let data = await downloadedOrderWord(this.$axios, id)
					if (data.status == 200) {
						this.downloadDOM.href = data.config.url
						this.downloadDOM.click()
					}

			},
			//接单等待时长
			getOrderTime(value) {
				// return orderFn.getProcessingTime(val, 1, this);
				//获取接单的时间戳
				// createDay = createDay.replace(/-/g, "/");
				let createTime = new Date(value).getTime();
				//获取当前的时间戳
				var nowTime = new Date().getTime();
				//获取处理时间戳
				let cha = nowTime - createTime;

				function IsNaN(value) {
					return typeof value === 'number' && isNaN(value);
				}
				if (IsNaN(cha)) {
					return ''
				}
				//转换天数
				// let day = Math.floor(cha / 1000 / 60 / 60 / 24);

				let round2 = (cha / 1000 / 60 / 60 / 24).toFixed(2)
			 	let	processingTime = (Math.ceil(round2 * 10) / 10).toFixed(1)
				if (processingTime < 0) {
					return '0.0'
				}  else if (processingTime < 0.1) {
					return '0.1'
				} else {
					return processingTime;
				}

				// if (day < 0) {
				// 	//不够一天显示小时
				// 	let hour = Math.round((cha / 1000 / 60 / 60) % 24);
				// 	processingTime = (hour / 24).toFixed(1)
				// }
				// return processingTime;
			},
			handleFilterChange(filters) {},
			//导出要导出所有页的数据
			exportExcel(name, type) {
				// let parms = {status: "待接单",paging:2}
				this.paramsByOrder.perPage = 99999999
				if(this.$store.state.user.role_id==4){
					this.paramsByOrder.process_id=this.$store.state.user.id
				}
				getOrderList(this.$axios, this.paramsByOrder)
				.then(res => {
					if (res.data.code == 200) {
						this.tableData2 = res.data.data;
						exportExcel(this, name, type, "#orderTbTemp");
					}
				})
			},
			//勾选数据（只会保存当前页的合计数据的数组）
			handleSelectionChange(val) {
				let that = this;
				for (let key in val) {
					that.selectTableData[val[key].id] = val[key]
				}
			},

			getAllAgent() {
				this.$axios.get('api/user/process')
					.then(res => {
						if (res.data.code == 200) {
							// let arr = res.data.data;
							// for (let key in arr) {
							// 	//element的模糊匹配组件el-autocomplete指定：必须数组的每个元素是个对象，并且有value属性
							// 	arr[key].value = arr[key].name;
							// }
							// this.restaurants2 = arr;
							this.processOptions = res.data.data
						}
					})
					.catch(err => {
						this.$message({
							type: "err",
							message: err
						});
					});

			},

			search() {
				this.currentPage = 1
				for (var i = 0; i < this.conditionForm.condition.length; i++) {
					let a = this.conditionForm.condition[i].parameter
					if (this.conditionForm.condition[i].parameter === 'subimt_time') {
						this.paramsByOrder.start_time = this.submitTime[0]
						this.paramsByOrder.end_time = this.submitTime[1]
					}
					this.paramsByOrder[a] = this.conditionForm.condition[i].value
				}
				if (!this.paramsByOrder.process_id) {
					if (this.$store.state.user.role_id == 4) {
						this.paramsByOrder.process_id = this.$store.state.user.id;
					}
				}

				// 处理分页数据
				delete this.paramsByOrder.page

				// 处理排序状态
				delete this.paramsByOrder.sort_str
				delete this.paramsByOrder.sort_order
				this.$refs['orderTb'].clearSort()
				orderFn.getData(this.$axios, this.paramsByOrder, this)
				this.getMyinfo()
				this.showFilter = false
			},
			// 添加条件筛选
			addFilterCondition(item) {
				let filterItem = {
					value: '',
					label: item.label,
					parameter: item.parameter,
					key: Date.now()
				}

				if (this.conditionForm.condition.length > 0) {
					let conditionlabels = []
					for (let i = 0; i < this.conditionForm.condition.length; i++) {
						conditionlabels.push(this.conditionForm.condition[i].label)
					}
					let Check = conditionlabels.indexOf(item.label)
					Check == -1 ? this.conditionForm.condition.push(filterItem) : this.$message.error('请勿重复添加')
				} else {
					this.conditionForm.condition.push(filterItem)
				}

				this.showFilterCondition = false;
			},
			resetForm(formName) {
				this.$refs[formName].resetFields()
				this.$refs['orderTb'].clearSort()
				this.conditionForm.condition.forEach(v => {
					if (v.value) {
						v.value = null
					}
				});
				this.showFilterCondition = false
				this.submitTime = []
				this.formProcess = {}
				this.paramsByOrder = {
					status: "待接单"
				}
				this.$nextTick(() => {
					this.$refs[formName].clearValidate()
				})
				// this.getData()
				// this.showFilter = false
			},
			submitsearch(formName) {
					let that = this
					this.$refs[formName].validate((valid, prop) => {
						let props = []
						for (let k in prop) {
							props.push(prop[k][0].field)
							if (prop[k][0].message = '提交时间不能为空') {
								if (that.submitTime) {
									if(	that.submitTime.length > 0	) {
										that.$refs[formName].clearValidate([prop[k][0].field])
										let timeIndex = props.indexOf('提交时间不能为空')
										props.splice(timeIndex, 1)
									}
								} else {
									return false
								}
							}
						}
						if (props.length) {
							that.$refs[formName].validateField(props, (valid2) => {
								if(valid2) {
									return false;
								} else {
                  that.search()
								}
							})
						} else {
							that.search()
						}
					})
      },
      removeDomain(item) {
				this.showFilter = true
				delete this.paramsByOrder[item.parameter]
				let index = this.conditionForm.condition.indexOf(item)
				if (index !== -1) {
					this.conditionForm.condition.splice(index, 1)
				}
				if (item.label === '提交时间') {
					this.submitTime = []
					delete this.paramsByOrder.start_time
					delete this.paramsByOrder.end_time
				}
				this.search()
			},
			changInput () {
				this.$refs['conditionForm'].clearValidate();
			},
			// 表格排序
			tableSortChange(column) {
				if (column.order === 'descending') {
					this.paramsByOrder.sort_str = column.prop
					this.paramsByOrder.sort_order = 'desc'
				} else if (column.order === 'ascending') {
					this.paramsByOrder.sort_str = column.prop
					this.paramsByOrder.sort_order = 'asc'
				} else {
					delete this.paramsByOrder.sort_str
					delete this.paramsByOrder.sort_order
				}
				if (column.prop == 'process.name'
						|| column.prop == 'submitTime') {
					return
				}
				this.loading = true;
				if (!this.paramsByOrder.process_id) {
					if (this.$store.state.user.role_id == 4) {
						this.paramsByOrder.process_id = this.$store.state.user.id;
					}
				}
				this.$axios.get('/api/order', {
					params: this.paramsByOrder
				})

				.then(res => {
					this.loading = false;
					this.tableData = res.data.data;
					this.pageSize = res.data.page.per_page;
					this.tableSize = res.data.page.per_page;
					this.tableEnd = res.data.page.per_page;
					this.total = res.data.page.total;
					for(let i = 0; i < this.tableData.length; i++) {
						this.tableData[i].showBtns = false
					}
				})
			},
			gwm() {
            	//水印,非管理员要设置
				if (this.$store.state.user.role_id != 1
					&& this.$route.path != '/admin/register'
					&& this.$route.path != '/admin/personalCenter/dstribution'
					&& this.$route.path != '/admin/personalCenter/myPurse'
					&& this.$route.path != '/admin/activityList/activityConfig'
					&& this.$route.path != '/admin/activityList/sysConfig'
					&& this.$route.path !='/admin/login'
					&& this.$route.path != '/admin/agentImprove'
					&& this.$route.path != '/order/login') {
					let that = this;
					let gwm = require('gwm');
					gwm.creation({
						'txt': that.$store.state.user.name,
						'container': '.el-table', //#gwm
						'fontSize': 40
					})
				}
			},
		},
		watch: {
			tableData: {
				handler: function(val) {
					val.forEach(v => {
						v.imgArr = []
						v.imgArr2 = []
						if (v.thumb_imgs) {
							let arr = v.thumb_imgs.split('&')
							if (v.img) {
								let arr = v.img.split('&')
								for (let i in arr) {
									v.imgArr2.push(this.baseUrl + '/storage/upload/' + arr[i])
								}
							}
							for (let i in arr) {
								v.imgArr.push(this.baseUrl + '/storage/upload/' + arr[i])
							}
						}
					})
				},
				immediate: true
			},
			tableHeader: {
				handler: function(val) {
					let arr = JSON.parse(JSON.stringify(val))
					delete arr.checked
					let select_all = true,
						checked = false
					for (let i in arr) {
						if (arr[i] == false) {
							select_all = false
						}
						if (arr[i] == true) {
							checked = true
						}
					}
					this.checked99 = checked
					if (select_all) {
						this.tableHeader.checked = true
					} else {
						this.tableHeader.checked = false
						// this.checked99 = false
					}

					this.table_show = false
					this.$nextTick(() => {
						this.table_show = true
						// this.$refs['orderTb']

					})
					this.$refs['orderTb'].doLayout()
					setTimeout(() => {
						this.$nextTick(() => {
							this.gwm()
						})
					}, 300)
				},
				deep: true
			}
		},
		beforeUpdate() {
			// this.$nextTick(() => {
			// 	this.$refs.orderTb.doLayout();
			// });
		},
	};
</script>

<style lang="less" scoped>
	.pendingDisposal {
    height: 100%; //撑满表格
    .el-table {
      width: 99.9% !important;
    }
  }
	.el-main .ivu-poptip .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner {
		min-width: 480px;
		// height: 300px;
		overflow-y: scroll;

	}

	.el-dropdown {
		font-size: 12px;
		margin: 0 5px;
		color: #2d8cf0;
	}

	.poptip-condition {
		display: block;
		margin-top: 10px;

		.poptip-condition-item {
			line-height: 25px;
			cursor: pointer;
		}

		.poptip-condition-add {
			font-size: 14px;
		}
	}

	.demo-dynamic {
		padding-left: 10px;

		.el-form-item {
			margin-bottom: 12px;
		}

		.el-input {
			width: 240px;
		}

		.el-date-editor {
			width: 240px;
		}

		.el-button {
			padding: 9px 15px;
			vertical-align: baseline;
		}

		.el-form-item__error {
			padding-top: 0;
		}
	}

	.el-main .poptip-condition .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner {
		min-width: 180px;
	}

	.down-execel {
		display: block;
		height: 40px;
		line-height: 40px;
		color: #333333;
		font-size: 14px;
		float: right;
		margin-right: 20px;

	}

	.btns {
		margin-top: 10px;

	}

	.tableLastCol {
		padding-right: 14px;
	}

	.tableLastCol1 {
		padding-right: 14px;
	}
	.el-table {
		.img-wrap {
			display: flex;
			justify-content: flex-start;
			> div {
				height: 23px;
			}
			.el-image {
				width: 23px;
				height: 23px;
				margin-right: 5px;

			}
		}
	}
	.leaveWord {
		color: rgb(16, 133, 16);
		font-size: 18px;
	}
</style>
